package com.usian.controller;

import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @GetMapping("/h1")
    public String h1(){
        return "h1";
    }

    @RequestMapping("/succList")
    public String succList(){
        return "succList";
    }

    @RequestMapping("/failList")
    public String failList(){
        return "failList";
    }

    public static void main(String[] args) {

        BCryptPasswordEncoder b= new BCryptPasswordEncoder();
        String encode = b.encode("123456");
        System.out.println(encode);

        boolean b1 = b.matches("1234567", "$2a$10$EsXCfUL2BfI3Bwu2mFOkNuWCRQmpd8qB45BQV9YvpY8zt9.MsdNoK");
        System.out.println(b1);
    }



    @Secured({"ROLE_admin","ROLE_sale"})
    @RequestMapping("/h2")
    public String h2(){
        return "h2";
    }

    @PreAuthorize("hasPermission('admin','cart')")
    @RequestMapping("/h3")
    public String h3(){
        return "h3";
    }

    @PreAuthorize("hasRole('ROLE_admin')")
    @RequestMapping("/query")
    public String query(){
        return "query";
    }

}
